// pages/shop_admission/index.js
var app = getApp();
var md5 = require('../../utils/md5.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    agreement: false,
    buttone: false,
    shop_add_money: 0,
    classifyViewed: 0,
    hangye_child:[],
    hangye_id:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //检测是否支付
    var service = 'Shop.CheckShopOrder'
    var user_id = wx.getStorageSync('user_id');
    var openid = wx.getStorageSync('openid');
    var sign = md5.md5(openid + service + user_id);
    wx.request({
      url: app.globalData.apiUrl + '?service=' + service,
      header: {
        'Content-Type': 'json'
      },
      data: {
        sign: sign,
        user_id: user_id,
        openid: openid
      },
      success: function (res) {
        if (res.data.data.code == 1) {
          wx.navigateTo({
            url: "/pages/shop_admission/index"
          });
        }
      }
    })
    that.hangyeAll()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  hangyeAll:function(){
    var that = this;
    var service = 'Shop.HangyeAll'
    var user_id = wx.getStorageSync('user_id');
    var openid = wx.getStorageSync('openid');
    var sign = md5.md5(openid + service + user_id);
    wx.request({
      url: app.globalData.apiUrl + '?service=' + service,
      header: {
        'Content-Type': 'json'
      },
      data: {
        sign: sign,
        user_id: user_id,
        openid: openid
      },
      success: function (res) {
        //console.log(that.data)
        that.setData({
          hangye: res.data.data.info,
          hangye_child: res.data.data.info[0].hangye_child,
          hangye_id: res.data.data.info[0].hangye_id
        });
      }
    })
  },
  tapClassify:function(e){
    var that = this;
    var key = e.currentTarget.dataset.index
    var id = e.currentTarget.dataset.id
    that.setData({
      classifyViewed: key,
      hangye_child: that.data.hangye[key].hangye_child,
      hangye_id:id
    });
  },
  toDetailsTap:function(e){
    wx.navigateTo({
      url: "/pages/shop_add/index?id=" + e.currentTarget.dataset.id
    })
  }
})